package com.alibaba.citrus.ots.price.ability.functions.factory.activity;

import com.alibaba.acm.shaded.com.alibaba.metrics.StringUtils;
import com.alibaba.citrus.ots.common.util.DateUtils;
import com.alibaba.citrus.ots.price.ability.functions.entity.activity.ActivityTermIndexEntity;
import com.epoch.app.otspricecenter.api.activityquery.dto.QueryPromotionPageListRequest;
import com.epoch.app.otspricecenter.model.dto.ActivityTermIndexSDO;
import com.epoch.app.otspricecenter.model.dto.DropBoxViewRequest;

import java.util.Date;

/**
 * @author hanguo
 * @date 2021/11/3
 * @Description 营销活动ES 工厂
 */
public class ActivityTermIndexFactory {


    public static ActivityTermIndexEntity create(QueryPromotionPageListRequest activityQueryViewRequest){

        if(StringUtils.isNotBlank(activityQueryViewRequest.getItemCode())){
            activityQueryViewRequest.setItemId(activityQueryViewRequest.getItemCode());
        }
        ActivityTermIndexSDO activityTermIndexSDO = new ActivityTermIndexSDO();
        activityTermIndexSDO.setActivityId(activityQueryViewRequest.getActivityId());
        activityTermIndexSDO.setActivityNoteName(activityQueryViewRequest.getActivityName());
        activityTermIndexSDO.setActivityTypeId(activityQueryViewRequest.getActivityTypeId());
        activityTermIndexSDO.setActivityStatus(activityQueryViewRequest.getActivityStatus());
        activityTermIndexSDO.setActivityStartDate(activityQueryViewRequest.getActivityStartDate()==null?null:activityQueryViewRequest.getActivityStartDate().getTime());
        activityTermIndexSDO.setActivityEndDate(activityQueryViewRequest.getActivityEndDate()==null?null:activityQueryViewRequest.getActivityEndDate().getTime());
        activityTermIndexSDO.setClientId(activityQueryViewRequest.getClientId());
        activityTermIndexSDO.setSalesOrganizationId(activityQueryViewRequest.getSalesOrganizationId());
        activityTermIndexSDO.setSalesChannel(activityQueryViewRequest.getChannelId());
        activityTermIndexSDO.setItemId(activityQueryViewRequest.getItemId());
        activityTermIndexSDO.setStart(activityQueryViewRequest.getStart());
        activityTermIndexSDO.setLimit(activityQueryViewRequest.getLimit());
        Date orderStartDate = DateUtils.obtainCurrentDayBeginOrEnd(activityQueryViewRequest.getOrderStartDate(), true);
        activityTermIndexSDO.setOrderStartDate(orderStartDate==null?null:orderStartDate.getTime());
        return ActivityTermIndexEntity.of(activityTermIndexSDO);
    }

    public static ActivityTermIndexEntity create(DropBoxViewRequest dropBoxViewRequest){
        ActivityTermIndexSDO activityTermIndexSDO = new ActivityTermIndexSDO();
        activityTermIndexSDO.setStart(dropBoxViewRequest.getStart());
        activityTermIndexSDO.setLimit(dropBoxViewRequest.getLimit());
        activityTermIndexSDO.setFeatures(dropBoxViewRequest.getQuery());
        activityTermIndexSDO.setCodeList(dropBoxViewRequest.getCodeList());
        return ActivityTermIndexEntity.of(activityTermIndexSDO);
    }


}
